package com.code.wflow.service.impl;

import com.code.wflow.mapper.FormItemMapper;
import com.code.wflow.model.FormItem;
import com.code.wflow.service.FormItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 流程定义中的表单(FormItem)表服务层
 *
 * @author ggh
 * @date 2023/02/23
 */
@Service
public class FormItemServiceImpl implements FormItemService {
    @Autowired
    private FormItemMapper formItemMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public FormItem queryById(Long id) {
        return this.formItemMapper.queryById(id);
    }


    /**
     * 通过workflowId查询数据
     *
     * @param workflowId 主键
     * @return 实例对象
     */
    @Override
    public List<FormItem> queryByWorkflowId(Long workflowId) {
        return this.formItemMapper.queryByWorkflowId(workflowId);
    }

    /**
     * 新增数据
     *
     * @param formItem 实例对象
     * @return 实例对象
     */
    @Override
    public boolean insert(FormItem formItem) {
        return this.formItemMapper.insert(formItem) > 0;
    }

    /**
     * 新增数据
     *
     * @param formItemList 实例对象
     * @return 实例对象
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean insertList(List<FormItem> formItemList) {
//        if (this.formItemMapper.insertList(formItemList) > 0) {
//            return true;
//        }
        throw new RuntimeException();
    }

    /**
     * 修改数据
     *
     * @param formItem 实例对象
     * @return 实例对象
     */
    @Override
    public boolean update(FormItem formItem) {
        return this.formItemMapper.update(formItem) > 0;
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.formItemMapper.deleteById(id) > 0;
    }

    /**
     * 通过主键删除数据
     *
     * @param idList 主键
     * @return 是否成功
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean deleteByIdList(List<Long> idList) {
        if (this.formItemMapper.deleteByIdList(idList) == idList.size()) {
            return true;
        }
        throw new RuntimeException();
    }
}
